import request from '@/utils/request';
import { requestWrapper, randomDate } from '@/utils/mock';

// 用户登录
export function login(data) {
  return requestWrapper(
    // 真实API请求
    () => request({
      url: '/auth/login',
      method: 'post',
      data
    }),
    // 模拟数据
    {
      token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
      tokenExpireTime: 86400,
      refreshToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'
    }
  );
}

// 获取验证码
export function getCaptcha() {
  return requestWrapper(
    // 真实API请求
    () => request({
      url: '/auth/captcha',
      method: 'get'
    }),
    // 模拟数据
    {
      captchaId: Math.random().toString(36).substring(2),
      captchaImage: ''
    }
  );
}

// 刷新令牌
export function refreshToken(data) {
  return requestWrapper(
    // 真实API请求
    () => request({
      url: '/auth/refresh-token',
      method: 'post',
      data
    }),
    // 模拟数据
    {
      token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
      tokenExpireTime: 86400,
      refreshToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'
    }
  );
}

// 用户注销
export function logout() {
  return requestWrapper(
    // 真实API请求
    () => request({
      url: '/auth/logout',
      method: 'post'
    }),
    // 模拟数据
    null
  );
}

// 获取当前用户信息
export function getUserInfo() {
  return requestWrapper(
    // 真实API请求
    () => request({
      url: '/auth/info',
      method: 'get'
    }),
    // 模拟数据
    {
      userId: 1,
      username: 'admin',
      nickname: '系统管理员',
      avatar: 'https://example.com/avatar.jpg',
      roles: ['admin'],
      permissions: ['system:user:list', 'system:user:add', 'system:user:edit', 'system:user:delete', 'system:role:list'],
      menus: [
        {
          name: '系统管理',
          path: '/system',
          icon: 'setting',
          children: [
            {
              name: '用户管理',
              path: '/system/user',
              icon: 'user'
            },
            {
              name: '角色管理',
              path: '/system/role',
              icon: 'peoples'
            },
            {
              name: '菜单管理',
              path: '/system/menu',
              icon: 'tree-table'
            },
            {
              name: '部门管理',
              path: '/system/dept',
              icon: 'tree'
            },
            {
              name: '岗位管理',
              path: '/system/post',
              icon: 'post'
            },
            {
              name: '字典管理',
              path: '/system/dict',
              icon: 'dict'
            }
          ]
        },
        {
          name: '系统监控',
          path: '/monitor',
          icon: 'monitor',
          children: [
            {
              name: '在线用户',
              path: '/monitor/online',
              icon: 'online'
            },
            {
              name: '服务监控',
              path: '/monitor/server',
              icon: 'server'
            },
            {
              name: '缓存监控',
              path: '/monitor/cache',
              icon: 'redis'
            },
            {
              name: '定时任务',
              path: '/monitor/job',
              icon: 'job'
            }
          ]
        }
      ]
    }
  );
}

// 修改个人密码
export function updatePassword(data) {
  return requestWrapper(
    // 真实API请求
    () => request({
      url: '/auth/password',
      method: 'put',
      data
    }),
    // 模拟数据
    null
  );
}

// 修改个人资料
export function updateProfile(data) {
  return requestWrapper(
    // 真实API请求
    () => request({
      url: '/auth/profile',
      method: 'put',
      data
    }),
    // 模拟数据
    null
  );
} 